package com.pac.questionnaire.service.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.common.tools.StringTools;
import com.common.util.ErrorNumber;
import com.common.util.LogicException;
import com.pac.file.service.FileService;
import com.pac.questionnaire.bean.QuestionnaireAnswerFileBean;
import com.pac.questionnaire.dao.QuestionnaireAnswerFileDao;
import com.pac.questionnaire.service.QuestionnaireAnswerFileService;

/**
 * 答卷答案对应的问卷Service实现
 * 
 * @author lujun.chen
 * @version [版本号, 2015年3月9日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Service(value = "questionnaireAnswerFileService")
public class QuestionnaireAnswerFileServiceImpl implements
		QuestionnaireAnswerFileService {

	private static Logger logger = Logger
			.getLogger(QuestionnaireAnswerFileServiceImpl.class);

	@Autowired
	private QuestionnaireAnswerFileDao questionnaireAnswerFileDao;
	
	@Autowired
	private FileService fileService;

	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public String addQuestionnaireAnswerFile(
			QuestionnaireAnswerFileBean questionnaireAnswerFileBean) {
		if (null == questionnaireAnswerFileBean) {
			logger.error("添加答卷答案对应的附件信息出错，参数为空");
			throw new LogicException(ErrorNumber.PARAM_IS_NULL, "参数为空");
		}

		if (StringTools.isNull(questionnaireAnswerFileBean.getFileId())) {
			logger.error("添加答卷答案对应的附件信息出错，文件ID为空");
			throw new LogicException(ErrorNumber.PARAM_IS_NULL, "文件ID为空");
		}

		if (StringTools.isNull(questionnaireAnswerFileBean.getPath())) {
			logger.error("添加答卷答案对应的附件信息出错，附件地址为空");
			throw new LogicException(ErrorNumber.PARAM_IS_NULL, "附件地址为空");
		}

		return questionnaireAnswerFileDao
				.addQuestionnaireAnswerFile(questionnaireAnswerFileBean);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean delQuestionnaireAnswerFile(
			QuestionnaireAnswerFileBean questionnaireAnswerFileBean) {
		if (null == questionnaireAnswerFileBean) {
			logger.error("删除答卷答案附件信息出错，参数为空");
			throw new LogicException(ErrorNumber.PARAM_IS_NULL, "参数为空");
		}

		if (StringTools.isNull(questionnaireAnswerFileBean.getDiagnosisId())) {
			logger.error("删除答卷附件信心出错，答卷ID为空");
			throw new LogicException(ErrorNumber.PARAM_IS_NULL, "答卷ID为空");
		}
		return questionnaireAnswerFileDao
				.delQuestionnaireAnswerFile(questionnaireAnswerFileBean);
	}

	@Override
	public List<QuestionnaireAnswerFileBean> queryQuestionnaireAnswerFile(
			QuestionnaireAnswerFileBean questionnaireAnswerFileBean) {
		return questionnaireAnswerFileDao
				.queryQuestionnaireAnswerFile(questionnaireAnswerFileBean);
	}

	

}
